package com.example.execise1.controller;

import com.example.execise1.service.HeroService;
import com.example.execise1.dto.HeroInfo;
import com.example.execise1.dto.HeroTypeData;
import com.example.execise1.dto.SkinInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api(tags = {"王者荣耀"})
@RequestMapping("/api")
@RestController
public class Unit5Controller {
    private final HeroService heroService;

    public Unit5Controller(HeroService heroService) {
        this.heroService = heroService;
    }

    @ApiOperation("创建一个皮肤数据功能")
    @PostMapping("/skin-infos")
    public ResponseEntity createSkin(@RequestBody SkinInfo skinInfo){
        if (skinInfo == null || skinInfo.getId() != null) {
            return ResponseEntity.badRequest().body("皮肤对象格式不正确");
        }
        SkinInfo result = heroService.createSkin(skinInfo);
        return ResponseEntity.ok(result);
    }

    @ApiOperation("更新指定英雄的次要分类API")
    @PutMapping("/hero-infos/type2")
    public ResponseEntity updateHeroType(@RequestParam Integer id,@RequestParam Integer newTypeId){
        HeroInfo result = heroService.updateHeroType(id,newTypeId);
        return ResponseEntity.ok(result);
    }

    @ApiOperation("统计各类型英雄数量API，按类型id升序排序")
    @GetMapping("/hero-infos/type-count")
    public ResponseEntity getHeroCount(){
        List<HeroTypeData> result = heroService.getHeroCount();
        return ResponseEntity.ok(result);
    }

    @ApiOperation("按分类名称查询英雄列表API，分页返回")
    @GetMapping("/hero-infos/hero-type")
    public ResponseEntity getTypeName(@RequestParam String typeName,@RequestParam Integer page,@RequestParam Integer size){
        Page<HeroInfo> result = heroService.getTypeName(typeName, page, size);
        return ResponseEntity.ok(result);
    }

    @ApiOperation("随机选取五个英雄组成一个队伍，包含法师、射手、辅助、战士或坦克、刺客各一名；" +
            "第一位为战士或坦克型英雄、第二位为法师型英雄、第三位为射手型英雄、第四位为辅助型英雄、第五位为刺客型英雄")
    @GetMapping("/hero-infos/team")
    public ResponseEntity getHeroTeam(){
        //创建英雄列表
        List<HeroInfo> result = new ArrayList<>();

        HeroInfo result1 = heroService.getTank();//战士或坦克
        HeroInfo result2 = heroService.getMage();//法师
        HeroInfo result3 = heroService.getStriker();//射手
        HeroInfo result4 = heroService.getAuxiliary();//辅助
        HeroInfo result5 = heroService.getAssassin();//刺客

        result.add(result1);
        result.add(result2);
        result.add(result3);
        result.add(result4);
        result.add(result5);

        return ResponseEntity.ok(result);
    }
}